package com.beans;
import java.sql.*;
import java.text.DateFormat;
import java.text.SimpleDateFormat;

import javax.servlet.http.*;

import org.apache.struts.action.*;


public class NoticeForm extends ActionForm{
	
	    int noticeId;
	    String title;
	    String description;
	    String creatorId;
	    Date createdDate;
	    String expirationDate;
	    String creatorName;
	    int categoryId;
	    String categoryName;
	    
	    public String getCreatorName() {
			return creatorName;
		}
		public void setCreatorName(String cretorName) {
			this.creatorName = cretorName;
		}
		public int getNoticeId() {
			return noticeId;
		}
		public void setNoticeId(int noticeId) {
			this.noticeId = noticeId;
		}
		public String getTitle() {
			return title;
		}
		public void setTitle(String title) {
			this.title = title;
		}
		public String getDescription() {
			return description;
		}
		public void setDescription(String description) {
			this.description = description;
		}
		public String getCreatorId() {
			return creatorId;
		}
		public void setCreatorId(String creatorId) {
			this.creatorId = creatorId;
		}
		public Date getCreatedDate() {
			return createdDate;
		}
		public void setCreatedDate(Date createdDate) {
			this.createdDate = createdDate;
		}
		public String getExpirationDate() {
			return expirationDate;
		}
		public void setExpirationDate(String expirationDate) {
			this.expirationDate = expirationDate;
		}
		public int getCategoryId() {
			return categoryId;
		}
		public void setCategoryId(int categoryId) {
			this.categoryId = categoryId;
		}
	    public String getCategoryName() {
			return categoryName;
		}
		public void setCategoryName(String categoryName) {
			this.categoryName = categoryName;
		}
	    
	    @Override
	    public String toString() {
	    // TODO Auto-generated method stub
	    return "id="+noticeId+",title="+title+",description="+description+",creator id="+creatorId+"creator name="+creatorName+",creator date="+createdDate;
	    }
	    
	    
	    @Override
		public ActionErrors validate(ActionMapping mapping,
				HttpServletRequest request) {
			
			ActionErrors errors = new ActionErrors();
			ActionError error;
			
			DateFormat dateFormat = new SimpleDateFormat("dd-MM-yyyy");
			java.util.Date d=new java.util.Date();
			
			String currentDate = dateFormat.format(d);
			System.out.println(currentDate+"..............."+expirationDate);
            
		/*	if (currentDate.compareTo(expirationDate) > 0) {
				error = new ActionError("notice.validcurrentDateRequired");
				errors.add("expirationDate", error);

			}*/

			if (expirationDate == null || expirationDate.length() == 0) {
				error = new ActionError("notice.ExpirationDateRequired");
				errors.add("expirationDate", error);
			}
			
			if (title == null || title.length() == 0) {
				error = new ActionError("notice.postTitleRequired");
				errors.add("title", error);
			}
			
			if (title.length()>100) {
				error = new ActionError("notice.titlelength");
				errors.add("titlelength", error);
			}
			
			
			if (description == null || description.length() == 0) {
				error = new ActionError("notice.descriptionRequired");
				errors.add("description", error);
			}
			
			if (description.length()>500) {
				error = new ActionError("notice.descriptionlengthRequired");
				errors.add("descriptionlength", error);
			}

			return errors;
		}


}
